let BASE_URL = "http://127.0.0.1:5000"
import axios from 'axios'

// import { get, post, postJson} from '@/utils/api'
const service = axios.create({
    headers: {
        'Cache-Control': 'no-cache',
        'Pragma': 'no-cache'
    },
    baseURL: BASE_URL,
})

export function get(url, params) {
    const headerJSON = {
        "Content-Type": "application/x-www-form-urlencoded"
    };
    return new Promise((resolve, reject) => {
        service.get(url, {
            params: params
        }, { headers: headerJSON }).then(res => {
            resolve(res);
        }).catch(err => {
            reject(err)
        });
    });
}

export function post(url, params) {

    return new Promise((resolve, reject) => {
        const headerJSON = {
            "Content-Type": "application/x-www-form-urlencoded"
        };
        service.post(url, JSON.stringify(params), { headers: headerJSON })
            .then(res => {
                resolve(res);
            })
            .catch(err => {
                reject(err)
            });
    });
}

export function postJson(url, params) {
    return new Promise((resolve, reject) => {
        const headerJSON = {
            "Content-Type": "application/json"
        };
        service.post(url, JSON.stringify(params), { headers: headerJSON })
            .then((res) => {
                resolve(res);
            })
            .catch(err => {
                reject(err)
            });
    })
}